package cn.yunyichina.provider.pay.kafka;

import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException;

/**
 * Created by Lullaby on 2016/10/24.
 */
public class AppTestConsumer {

    @Test
    public void test() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        context.start();
        DirectChannel queueChannel = (DirectChannel) context.getBean("outputFromKafka");
        queueChannel.subscribe(new MessageHandler() {
            @Override
            public void handleMessage(Message<?> message) throws MessagingException {
                System.out.println(message.getHeaders());
                System.out.println(message.getPayload());
            }
        });
//        while ((message = queueChannel.receive(-1)) != null) {
//            String tr = (String) message.getPayload();
//            System.out.println(tr);
//        }
    }

}
